package com.chief.lesson1;


import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class StreamWordCount {

    public static void main(String[] args) throws Exception {
        //environment阶段
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();

        // source阶段
        DataStreamSource<String> dataStreamSource = environment.readTextFile("E:\\bigdata-start\\flink\\flinkCode\\src\\main\\java\\com\\chief\\lesson1\\hello.txt");

        //transform阶段
        SingleOutputStreamOperator<Tuple2<String, Integer>> sum = dataStreamSource.flatMap(new WordCount.MyFlatMapFunction())
                .keyBy(value -> value.f0).sum(1);

        //sink阶段
        sum.print();

        environment.execute();

    }

}
